package com.xmg.boot.demo.bootlesson1.user.controller;

import com.xmg.boot.demo.bootlesson1.user.annotation.StartSwaggerScan;
import com.xmg.boot.demo.bootlesson1.user.entity.Result;
import com.xmg.boot.demo.bootlesson1.user.entity.ResultUtil;
import com.xmg.boot.demo.bootlesson1.user.entity.dm.DmTable;
import com.xmg.boot.demo.bootlesson1.user.entity.dto.StudentDto;
import com.xmg.boot.demo.bootlesson1.user.entity.pojo.Student;
import com.xmg.boot.demo.bootlesson1.user.entity.pojo.User;
import com.xmg.boot.demo.bootlesson1.user.service.StudentService;
import com.xmg.boot.demo.bootlesson1.user.service.dm.DmTableService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author mwd
 * @create 2023-11-22
 */

@StartSwaggerScan
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private DmTableService dmTableService;

//    @ApiOperation(value="简单查询",notes="单表查询")
//    @GetMapping("/stuIndex")
//    public Result<List<Student>> Index(){
//        List<Student> lst= studentService.list();
//        return ResultUtil.success(lst);
//    }

    @ApiOperation(value="多表联查",notes="多表多条件查询")
    @GetMapping("/getList")
    public Result<List<StudentDto>> GetList(@RequestParam("sName") String sName
            ,@RequestParam("cId") int cId){
        List<StudentDto> lst = studentService.getStudentLst(sName, cId);
        return ResultUtil.success(lst);
    }


    @ApiOperation(value="DM数据库",notes="单表查询")
    @GetMapping("/getDMList")
    public Result<List<DmTable>> GetDMList(){
        List<DmTable> lst = dmTableService.getSelectAll();
        return ResultUtil.success(lst);
    }


    @ApiOperation(value = "Redis测试",notes = "测试")
    public void Redis(){
        // String
        redisTemplate.opsForValue().set("name","张三");
        System.out.println(redisTemplate.opsForValue().get("name"));
    }
}
